<?php

$url = 'http://test.cicore/maintainApi/RepairOrder/create_order_new';
$orderData = array (
    'repair_point' => 'es',
    'source_name' => 'http://tomrepair.es/',
    'source_site_id' => '12',
    'create_time' => '2016-06-28 05:40:52',
    'quantity' => 1,
    'reference_order_number' => '',
    'repair_type' => '1',
    'merchant_num' => '17',
    'customer_name' => '(last name first name) ',
    'customer_phone' => '3123',
    'customer_email' => 'david@pandaclever.es',
    'pickup_address' => 'street address city 312 zip PT',
    'delivery_address' => 'street address',
    'pickup_service' => 0,
    'website_origin' => '2',
    'delivery_service' => 1,
    'storeOrShip' => '1',
    'products_list' =>
        array (
            0 =>
                array (
                    'defectDes' => 'reamark',
                    'imei' => 'imei',
                    'remark_customer' => 'cannot boost or charge',
                    'source_id_order' => '',
                    'productSku' => 'sku63623',
                    'category' => 1,
                    'product_brand' => 'ELEPHONE',
                    'brandCustomerNum' => '24',
                    'product_model' => 'G1',
                ),
        ),
    'remark' => 'remark',
    'delivery_country' => 'PT',
    'delivery_city' => 'city',
    'delivery_state' => '312',
    'delivery_zipcode' => 'zip',
    'pickup_country' => 'PT',
    'pickup_city' => 'city',
    'pickup_state' => '312',
    'pickup_zipcode' => 'zip',
);
$pushData = array(
    'user' => 'flowrepair',
    'key' => 'flowTokenPwd',
    'orders' => json_encode($orderData),
);
$requestData = vpost($url, $pushData);
var_dump($requestData);


function vpost($url, $data, $headers = array())
{
    $curl = curl_init(); // 启动一个CURL会话
    if ($headers && is_array($headers)) {
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    }
    curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
    curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
    curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
    curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
    curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
    $tmpInfo = curl_exec($curl); // 执行操作
    if (curl_errno($curl)) {
        echo 'Errno' . curl_error($curl);
    }
    curl_close($curl); // 关键CURL会话
    return $tmpInfo; // 返回数据
}
